package cn.bmbanjia.zebra2024.apps.laddieAndroid.user.controller;

import cn.bmbanjia.zebra2024.apps.base.laddie.service.ILaddieService;
import cn.bmbanjia.zebra2024.apps.laddieAndroid.user.req.LoginReq;
import cn.bmbanjia.zebra2024.apps.laddieAndroid.user.resp.LaddieAndroidCurrentUserResp;
import cn.bmbanjia.zebra2024.apps.laddieAndroid.satoken.LaddieAndroidCurrentUser;
import cn.bmbanjia.zebra2024.apps.laddieAndroid.satoken.StpLaddieAndroidUtil;
import cn.bmbanjia.zebra2024.frame.resp.Resp;
import io.github.linpeilie.Converter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 小哥信息 控制层。
 *
 * @author fugui
 * @since 2024-07-10
 */
@Tag(name = "小哥androidAPP用户")
@RestController
@RequestMapping("/laddieAndroid/user")
public class LaddieAndroidUserController {

    @Resource
    private ILaddieService laddieService;

    @Resource
    private Converter converter;

    @Operation(summary = "当前用户")
    @PostMapping("/current")
    public Resp<LaddieAndroidCurrentUserResp> current() {
        LaddieAndroidCurrentUser laddieAndroidCurrentUser = StpLaddieAndroidUtil.currentUser();
        LaddieAndroidCurrentUserResp currentUserResp = converter.convert(laddieAndroidCurrentUser, LaddieAndroidCurrentUserResp.class);
        return Resp.success(currentUserResp);
    }

    @Operation(summary = "登录")
    @PostMapping("/login")
    public Resp<Void> login(@RequestBody @Valid LoginReq req) {
        LaddieAndroidCurrentUser currentUser = converter.convert(req, LaddieAndroidCurrentUser.class);
        StpLaddieAndroidUtil.login(currentUser);
        return Resp.success();
    }

}
